
/**
 * 借款单、报销单通用的前台逻辑放此，有不同的在各自的js中完成
 */
var isAction = false; //是否需要触发方法 busItemTabRowChange1
var isRefresh = false;//是否是刷新操作
var isSave = false;//是否是保存操作
var isCopy = false;//是否复制操作
var isLoad = false;//是否为单据加载时 
var isCydj = false;//是否设置了常用单据
var isAdd = false;//是否新增单据操作

/*重置标志位*/
function $resetPageStatus(){
	window.isNewCjkDialog = true;
	billUI.eventHandler.noCjk = true;
	isRefresh = false;//是否是刷新操作
	isSave = false;//是否是保存操作 
	isCopy = false;//是否复制操作
	isLoad = false;//是否为单据加载时
	isAdd = false;
}

/**
 * 初始化
 */
function postInit() {
	/*以下方法都是重写PfBilleventhandler中的*/
	billUI.eventHandler.onBoSave = JkbxSave;
	billUI.eventHandler.doOnBoDelete = jkbxDelete;
	billUI.eventHandler.commitAudit = jkbxApprove;
	billUI.eventHandler.onBoCancelAudit = jkbxUnApprove;
	billUI.eventHandler.onBoCopyAdd  = jkbxCopy;
	billUI.eventHandler.onBeforeBoEdit = jkbxBeforeEdit;//编辑修改前
	billUI.eventHandler.onBoAudit = jkbxAudit//审批操作

	billUI.eventHandler.onAfterBoCard = jkbxAfterBoCard;
	billUI.eventHandler.onAfterBoList = jkbxAfterBoList;
	
	billUI.eventHandler.onBeforeBoAdd = jkbxBeforeAdd;
	billUI.eventHandler.onBeforeBoLineDel = jkbxBeforeLineDel;
	billUI.eventHandler.onAfterBoCancel = jkbxAfterBoCancel;
	billUI.eventHandler.onAfterBoLineDel = jkbxAfterBoLineDel;
	billUI.eventHandler.onBeforeBoRefresh = jkbxBeforeBoRefresh;
	billUI.eventHandler.onAfterBoRefresh = jkbxAfterBoRefresh;
	billUI.eventHandler.onBeforeBoLineCopy = jkbxBeforeBoLineCopy;
	billUI.eventHandler.onAfterBoLinePaste = jkbxAfterBoLinePaste;
	
	billUI.eventHandler.isTmpSaveStatus = jkbxIsTmpSaveStatus;
	billUI.eventHandler.onBeforeAction = jkbxBeforeAction;
	billUI.eventHandler.onAfterAction = jkbxAfterAction;
	billUI.eventHandler.getBillBussStatus = jkbxGetBillBussStatus;
	billUI.eventHandler.getBillType = jkbxGetBillType;
	billUI.eventHandler.getBillStatusValue = jkbxGetBillStatusValue;
	billUI.eventHandler.afterLoadHeadData = jkbxAfterLoadHeadData;
	billUI.eventHandler.externalInitBill = jkbxExternalInitBill;
	
	initParseBzbmPrecision();
	initJkBx();
}

function jkbxBeforeAdd(row){
	isAdd = true;
	return true;
}
/**
 *'行操作'中的'删行'之前操作
 */
function jkbxBeforeLineDel(row)
{
	var ds = this.getNowSubDs();
	var bodyTab = getComponent("bodyTab");
	var item = bodyTab.getSelectedItem();
	var tabcode = item.id;
	var colIndex = ds.nameToIndex('tablecode');
	return row.getCellValue(colIndex) == tabcode;
};


function jkbxBeforeEdit(){
}

/**
 * 自定义按钮的点击事件【冲借款、暂存、联查审批】
 */
function selfDefBtnFuc(btnNo)  
{ 
	var ds = getHeadDs();
	var arr = ds.getSelectedIndices();
	if(arr == null){
		showMessageDialog("${ml:trans('yer_jkbx001')}");
		return;
	}
	if(arr.length > 1){
		showMessageDialog("${ml:trans('yer_ex_onlyone')}");
		return;
	}
	var row = ds.getSelectedRow(); 
	//冲借款  
	if(btnNo.name == 201){
		$openCjk("normal");
	}
	//暂存 
	else if(btnNo.name == 202){ 
		if(billUI.billController.isPlatForm)
    		billUI.getEventHandler().onBoTmpSave();
	}else if(btnNo.name == 211){//联查审批
		var billId = row.getCellValue(ds.nameToIndex("pk_jkbx"))
		var billType = row.getCellValue(ds.nameToIndex("djlxbm"));
		var url = getCorePath() + "/pfinfo/pfinfo.jsp?pageId=pfinfo&billId="+ billId +"&billType=" + encodeURIComponent(billType) + "&rand=" + (Math.random()*10000).toString().substring(0, 4);
		showDialog(url , "${ml:trans('yer_jkbx002')}", "600", "450", "pfinfoDialog", true,true);
	} 
	else if(btnNo.name == 212){//联查预算执行情况
		var billId = row.getCellValue(ds.nameToIndex("pk_jkbx"))
		var djdl = row.getCellValue(ds.nameToIndex("djdl"));
		var url = getCorePath() + "/linkntb/linkntb.jsp?pageId=linkntb&billId=" + billId + "&djdl=" + djdl + "&rand=" + (Math.random()*10000).toString().substring(0, 4);
		showDialog(url , "${ml:trans('yer_linkntb_title')}", "750", "350", "ntbDialog", true,true);
	} 
	else if(btnNo.name == 203){//文档管理
		var pk_jkbx = row.getCellValue(ds.nameToIndex('pk_jkbx'));
		var url = getCorePath() + "/docmanage/docmanage.jsp?pageId=docmanage" 
				+ "&pk_jkbx=" + pk_jkbx
				+ "&rand=" + (Math.random()*10000).toString().substring(0, 4);
		showDialog(url , "${ml:trans('yer_filemanage_title')}", "550", "350", "attachmentDialog", true,true);
	}
}  

function initParseBzbmPrecision(){
	var str = getSessionAttribute('bzbm_precision_key');
	initParseBzbmPrecision1(str);
	var str = getSessionAttribute('bbhl_precision_key');
	initParseBzbmPrecision1(str,true);
}
function initParseBzbmPrecision1(str,flag){
	if(window.bzbmmap == null)
		window.bzbmmap = new HashMap();
	if(str == null || str == '')
		return;
	var arr = str.split("$");
	for(var i=0; i<arr.length; i++){
		var arr2 = arr[i].split("=");
		if(flag)//本币汇率的
			window.bzbmmap.put(arr2[0]+"_bbhl", arr2[1]);
		else
			window.bzbmmap.put(arr2[0], arr2[1]);
	}
}

/* 单据是否是暂存状态，在【保存】之前调用*/
function jkbxIsTmpSaveStatus(ds){
	var sRow = ds.getSelectedRow();
	var djzt = sRow.getCellValue(ds.nameToIndex('djzt'));
	return djzt == IBillStatus.DJZT_TempSaved;
}
/**
 * 在执行完子表增行操作后执行该方法 ，取代bxitemds的onBeforeRowInsert
 */
function jkbxBeforeBoLineAdd(row,subDs)
{
	//其他表体不进行处理
	if(subDs.id != 'bx_jkbxitems' && subDs.id != 'jk_items')
		return true;
	var headDs = getHeadDs();  
	var amountIndex = subDs.nameToIndex("amount");
	var szxmIndex = subDs.nameToIndex("szxmid");
	if(row == null) 
		return false;
	//表体增行之前，需要给表数据设置tabcode
	var colIndex = subDs.nameToIndex("tablecode");
	if(row.getCellValue(colIndex) == null){
		var bodyTab = getComponent("bodyTab");
		var item = bodyTab.getSelectedItem();
		var tabcode = item.name;
		if(tabcode == 'er_finitem' || tabcode == 'er_bxcontrast')
			return false;
		row.setCellValue(colIndex, tabcode);
	}
	//将表头的收支带入表体
	var headSzxm = headDs.getSelectedRow().getCellValue(headDs.nameToIndex('szxmid'));
	var amount = row.getCellValue(amountIndex);
	if(headSzxm != null){
		//常用单据不进行设置
		if(row.cydj == null){
			var bodySzxm = row.getCellValue(szxmIndex);
			//有可能是常用单据已经设置
			if(bodySzxm == null)
				row.setCellValue(szxmIndex,headSzxm,true);
		}
	}
	return true;
};

/*流程动作之前处理，重载PFBillEventHandler.js中方法*/
function jkbxBeforeAction(actionName, billType)
{ 
	var headDs = this.getMasterDs();
	var busitemDs = getSubDs();
	var djztIndex = headDs.nameToIndex('djzt');
	var flag = true;
	switch(actionName){
		case IPfAction.SAVE:
				if(headDs.id == 'bx_bxzb'){
					if(busitemDs != null && busitemDs.getRowCount() > 0 ){
						//业务信息页签的行数据变化对财务页签触发
						busItemTabRowChange1();
					}
				}
				headDs.setValueAt(headDs.getSelectedIndex(),djztIndex,IBillStatus.DJZT_TempSaved);
				dealZyMcToPK(headDs);
				//如果是暂存则将冲借款清空
				if(headDs.id == 'bx_bxzb'){
					if(!clernCjk())
						flag = false;
				}
				isSave = true;
				break;
		case IPfAction.APPROVE:
				break;
		case IPfAction.COMMIT:
				if(headDs.id == 'bx_bxzb'){
					if(busitemDs != null && busitemDs.getRowCount() > 0 ){
						busItemTabRowChange1();
					}
				}
				//校验
				if(!checkDs(headDs))
					return false;
				if(headDs.id == 'bx_bxzb'){
					if(!checkBusItemDs(busitemDs))
						return false;	
				}
				//清除业务页签中空行
				if(!deleteEmptyRow(busitemDs))
					return false;
				headDs.setValueAt(headDs.getSelectedIndex(),djztIndex,IBillStatus.DJZT_Saved);
				var isContrast = getSessionAttribute("IS_CONTRAST");
				if(headDs.id == 'bx_bxzb' && isContrast == 'Y'){
					if(!$beforeOpenCjkCheck())
						flag = false;
					/*判断借款人是否有未两清的借款单*/
					var value = getService("webbx_common_service").getJkd($getParamMap());
					var cjkybje = $f(headDs.getSelectedRow().getCellValue(headDs.nameToIndex('cjkybje')));
					if(value == 'Y' && billUI.eventHandler.noCjk){
						billUI.eventHandler.noCjk = true;//需要冲借款
						var dialog = ConfirmDialogComp.showDialog("${ml:trans('yer_jkbx003')}",yesTodo,notTodo,null,null,null,null);
						flag =  false;
					}
					else
						flag = true;
				}else if(headDs.id == 'jk_jkzb'){
					var ybje = headDs.getSelectedRow().getCellValue(headDs.nameToIndex('ybje'));
					if(ybje == null || $f(ybje) == 0){
						showMessageDialog("${ml:trans('yer_jkbx004')}");
						flag =  false;
					}
				}else{
					flag = true;
				}
				//用验证公式来验证这两个Ds
				if(executeValidateFormular(headDs)){
					flag =  false;
				}
				if(busitemDs != null && executeValidateFormular(busitemDs))
					flag =  false;
				isSave = true;
				if(flag){
					dealZyMcToPK(headDs);
				}
				break;
		case IPfAction.DELETE:
				break;
		case IPfAction.EDIT:
				break;
		case IPfAction.UNAPPROVE:
				break;
	}
	return flag;
};

/**
 * 单据操作后处理，重载PFBillEventHandler.js中方法
 */
function jkbxAfterAction(actionName, billType)
{ 
	this.billUI.setTotalUIStatus(null,this.getBillBussStatus());
	var headDs = this.getMasterDs();
	var itemDs = getSubDs();
	dealZyPKToMc(headDs);
	switch(actionName){
		case IPfAction.SAVE:
				setBbhlActive(headDs);
				this.onBoRefresh();
				break;
		case IPfAction.APPROVE:
				break;
		case IPfAction.COMMIT:
				setBbhlActive(headDs);
				this.onBoRefresh();
				break;
		case IPfAction.DELETE:
				resetBzbmAfterAction(headDs);
				break;
		case IPfAction.EDIT:  
				this.onBoRefresh();
				break;
		case IPfAction.UNAPPROVE:
				//this.onBoRefresh();//注释for： 列表下多选， 反审后checkbox不能选了
				break;
	}
	return true;  
};

/**
 * 单据操作后，[eg:save、delete、commit、edit],
 * 如果币种不是集团本位币，则需要将控件精度和金额数据精度重新设置
 */
function resetBzbmAfterAction(headDs){
	var row = headDs.getSelectedRow();
	if(row != null){
		var bzbm_value = row.getCellValue(headDs.nameToIndex('bzbm'));
		reset4Bzbm1(headDs,bzbm_value);
	}
}

function setBbhlActive(headDs){
	var form = null;
	if(headDs.id == 'bx_bxzb')
		form = getComponent("headTab_bxzb_form");
	else
		form = getComponent("headTab_jkzb_form");
	var bbhlEle = form.getElement("bbhl");
	if(bbhlEle != null) 
		bbhlEle.setActive(false);
}


/*载入数据后的处理*/
function jkbxExternalInitBill(headDs)
{
	dealZyPKToMc(headDs);//处理摘要
};

/*点击"卡片显示"按钮*/
function jkbxAfterBoCard()
{
	$('tailtr').style.display = "";
	var headDs = billUI.eventHandler.getMasterDs();
	var sRow = headDs.getSelectedRow();
	if(sRow != null){
		var bzbm_value = sRow.getCellValue(headDs.nameToIndex('bzbm'));
		var precision = window.bzbmmap.get(bzbm_value);	
		var bbhl_pre = window.bzbmmap.get(bzbm_value+"_bbhl");
		if(headDs.id == "bx_bxzb"){
			$resetBxPrecision([0,bbhl_pre,precision])
			resetJEForPrecision('bx');//这个里面的逻辑会影响金额的不一致，故去掉
		}
		else{
			$resetJkPrecision([0,bbhl_pre,precision]);
			resetJEForPrecision('jk');
		}
	}
};

/*点击"列表显示"按钮*/
function jkbxAfterBoList()
{ 
	$('tailtr').style.display = "none";
	var headDs = billUI.eventHandler.getMasterDs();
	var headGrid = (headDs.id == 'bx_bxzb') ? getComponent("headTab_bxzb_grid") : getComponent("headTab_jkzb_grid");
	if(headGrid != null){
		headGrid.setPaginationInfo();
	}
	var bxzbForm = (headDs.id == 'bx_bxzb') ? getComponent("headTab_bxzb_form") : getComponent("headTab_jkzb_form");
	if(bxzbForm != null) {
		var headDsFields = $$getDoubleCol(headDs);
		for(var i=0; i < headDsFields.length; i++){
			var formEle = bxzbForm.getElement(headDsFields[i]);
			if(formEle != null){
				var pre = formEle.getFormater().precision;
				//设置grid精度
				if(pre != null){
					var ele = headGrid.getHeader(headDsFields[i]);
					if(ele != null){
						ele.setPrecision(pre);
					}
				}
			}
			
		}
		//$resetHeadYB(headDs);//这个里面的逻辑会影响金额的不一致，故去掉
	}
};

/**
 * 取消操作后
 */
function jkbxAfterBoCancel(headDs)
{
	//需要将汇率字段设置为false
	var form = (headDs.id == "bx_bxzb") ? getComponent("headTab_bxzb_form") : getComponent("headTab_jkzb_form");
	var bbhlEle = form.getElement("bbhl");
	if(bbhlEle != null) 
		bbhlEle.setActive(false);
};

/**
 * 在执行完子表删行操作后执行该方法，修改表头数据
 */
function jkbxAfterBoLineDel(row){
	var headDs = this.getMasterDs();
	var nowSubDs = this.getNowSubDs();
	var newSum = nowSubDs.totalSum(["amount"], null, null, getSessionAttribute("precision"));
	var value = 0;
	if(newSum == '' || newSum == null){
		value = value.toFixed(parseInt(getSessionAttribute("precision")));
	}else
		value = newSum[0];
		
	if(nowSubDs.id == "bx_jkbxitems")
		headDs.setValueAt(headDs.getSelectedIndex(), headDs.nameToIndex("total"), value);//设置表头合计金额
	else
		headDs.setValueAt(headDs.getSelectedIndex(), headDs.nameToIndex("ybje"), value);//设置借款表头原币金额
};

/*行双击则切换到卡片页面*/
GridComp.prototype.onRowDblClick = function(rowIndex, row)
{ 
	return;//取消掉了，因为双击时如果表体还未加载会抛异常
	if(this.id != 'headTab_bxzb_grid' && this.id != 'headTab_jkzb_grid')
		return;
	billUI.getEventHandler().onBoCard();
		
	var headDs = this.model.dataset;
	var bzbm_value = headDs.getSelectedRow().getCellValue(headDs.nameToIndex('bzbm'));
	var precision = window.bzbmmap.get(bzbm_value);	
	if(headDs.id == "bx_bxzb")
		$resetBxPrecision1(precision);
	else
		$resetJkPrecision1(precision);
};

/**
 * 刷新前执行该方法
 */
function jkbxBeforeBoRefresh(){
	isRefresh = true;
};
/**
 * 刷新后执行该方法,更新按钮状态
 */
function jkbxAfterBoRefresh()
{ 
	if(isRefresh) 
		isRefresh = false;
	var headDs = this.getMasterDs(); 
	var value = null;
	if(headDs.getRowCount() != 0){
	   	var billStatus = this.billUI.billController.billStatusField;
	   	var row = headDs.getSelectedRow();
	   	if(row != null)
	   		value = row.getCellValue(headDs.nameToIndex(billStatus))
	}
	var state = null;
	if(value != null)
		state = IBillOperate.OP_NOTEDIT;
	dealZyPKToMc(headDs);
	$resetPageStatus();
   	this.billUI.setTotalUIStatus(state, value);
};

function jkbxGetBillBussStatus()
{
	var headDs = this.getMasterDs();
	var value = null;
	if(headDs.getRowCount() != 0){
	   	var billStatus = this.billUI.billController.billStatusField;
	   	var row = headDs.getSelectedRow();
	   	if(row != null)
	   		value = row.getCellValue(headDs.nameToIndex(billStatus))
	}
	return value;
};


/**获取单据的billType*/
function jkbxGetBillType(ds,row){
	return row.getCellValue(ds.nameToIndex('djlxbm'));
};

/**
 * 在执行行复制之前执行该方法，如果
 * 返回false, 则不继续执行操作。
 */
function jkbxBeforeBoLineCopy(copyRows){ 
		var subDs = this.getNowSubDs();
		if(subDs.id != 'bx_jkbxitems' || subDs.id != 'jk_items')
			return;
		var index1= subDs.nameToIndex("pk_busitem");
		var index2 = subDs.nameToIndex("pk_jkbx");
		for(var i=0;i<copyRows.length;i++){
			copyRows[i].setCellValue(index1,null);
			copyRows[i].setCellValue(index2,null);  
		}
};

/**
 * 返回web报销单据状态值
 */
function jkbxGetBillStatusValue(billStatusName)
{
	// 审批未通过
	if(billStatusName == IBillStatusName.NOPASS)
		return 2;
	// 审批通过	
	else if(billStatusName == IBillStatusName.CHECKPASS)
		return 1;
	// 审批进行中	
	else if(billStatusName == IBillStatusName.CHECKGOING)
		return 0;
	// 提交状态	
	else if(billStatusName == IBillStatusName.COMMIT)
		return -1;
	// 作废状态	
	else if(billStatusName == IBillStatusName.DELETE)
		return 4;
	// 冲销状态	
	else if(billStatusName == IBillStatusName.CX)
		return 5;	
	// 终止(结算）态
	else if(billStatusName == IBillStatusName.ENDED)
		return 6;
	// 冻结状态
	else if(billStatusName == IBillStatusName.FREEZE)
		return 7;
	// 自由态
	else if(billStatusName == IBillStatusName.FREE)
		return 8;
	else if(billStatusName == IBillStatusName.ALL)
		return 30;		
	else if(billStatusName == IBillStatusName.REJECT)	
		return 3;
}; 

/**
 * web报销的新增直接走BillEventHandler的新增,不走PFBillEventHandler的新增
 */
PFBillEventHandler.prototype.onBoAdd = function()
{	
	BillEventHandler.prototype.onBoAdd.call(this);

};

/*单据载入后调用*/
function jkbxAfterLoadHeadData(returnArgs, success)
{	 
	if(success){	
		isLoad = true;
		var headDs = returnArgs[1], oThis = returnArgs[2];
		if(headDs.getRowCount() > 0)
			headDs.setRowSelected(0);	
		setCheckMan(headDs);
		oThis.initBillBussStatus();
		//重设外币单据的精度
		var row = headDs.getSelectedRow();
		$resetDjPrecision(headDs, row);
	}
}; 

//判断某操作员是否是当前单据的审核人
function setCheckMan(headDs){
	
	clearCheckManMap();
	var billIds = new Array();
	var billType = "";
	for(var i=0,len = headDs.getRowCount(); i<len; i++){
		var row = headDs.getRow(i);
		var billId = row.getCellValue(headDs.nameToIndex('pk_jkbx'));
		billIds.push(billId);
		billType = row.getCellValue(headDs.nameToIndex('djlxbm')); 
	}
	if(billIds.length == 0 )
		return;
	var userId = getPkUser();
	var ids = getService("webbx_common_service").isCheckmanAry(billIds, billType, userId);
	for(var i=0;i<ids.length;i++){
		setCheckManMap(ids[i] + "ischeckman", "Y");
	}
}
 
function setCheckManMap(key,value){
	if(window.CheckManMap == null)
		window.CheckManMap = new HashMap();
	window.CheckManMap.put(key,value);
}
function getCheckManByKey(key){
	if(window.CheckManMap != null)
		return window.CheckManMap.get(key);
}
function clearCheckManMap(){
	if(window.CheckManMap != null)
		window.CheckManMap.clear();
}

/**
 * 在执行行粘贴操作之后执行该方法
 */
function jkbxAfterBoLinePaste()
{
	var nowSubDs = this.getNowSubDs();
	var oldRows = this.copyLineContent.get(nowSubDs);
	var index = nowSubDs.nameToIndex('amount');
	if(index != -1){
		var rowCount = nowSubDs.getRowCount();
		var oldRowCount = oldRows.length;
    	for(var i = rowCount-oldRowCount,j=0; i < rowCount,j<oldRowCount; i++,j++){
    		var oldValue = oldRows[j].getCellValue(index);
    		nowSubDs.setValueAt(i,index,oldValue,true);
		} 
	}
};


/*查询模板后，载入数据后处理ds*/
function afterQueryDataset(ds){
	if(this.billUI.currentPanel == ManageUI.CARDPANEL)
		billUI.getEventHandler().onBoList();
		
	var count = ds.getRowCount(); 
	if(count == 0)
		return;
	var zyIndex = ds.nameToIndex('zy');
	var zyMcIndex = ds.nameToIndex('zy_mc'); 
	for(var k=0;k<count;k++){
		var row = ds.getRow(k);
		var zy = row.getCellValue(zyIndex);
		if(zy != null && zy != ''){
			ds.setValueAt(k, zyMcIndex, zy);
		}
		$resetDjPrecision(ds,row);
	}
	setCheckMan(ds);
	ButtonManager.getInstance().updateButtons();
}

function dealRuleAction() {
	var isHK = getParameter('type');
	if(isHK != null)
		return;
	var headMap = getHeadDsMap();
	var headDataType = getHeadDsDataTypeMap();
	var bodyDsListMap = getBodyDsListMap();
	var bodyList = getBodyList();
	var bodyDataType = getBodyDsDataTypeList();
	/*
	var result = getService("webbx_common_service").getHeadReimAction(headMap,headDataType,bodyDsListMap,bodyDataType);
	if(result != null)
		setJkBxHeadDsValue(result);
	if(bodyDsListMap != null){
		var resultofbody = getService("webbx_common_service").getBodyReimAction(headMap,headDataType,bodyDsListMap,bodyList,bodyDataType);
		if(resultofbody != null) 
			setJkBxBodyDsValueAno(resultofbody);
	}
	*/
	
	/*表头，表体一起提交*/
	var result = getService("webbx_common_service").getHeadBodyReimAction(headMap,headDataType,bodyDsListMap,bodyDataType,bodyList);
	var v = eval(result);
	if(v[0] != null){
		setJkBxHeadDsValue(v[0]);		
	}
	if(v[1] != null){
		setJkBxBodyDsValueAno(v[1].split('$'));
	}
}
function doHeadDataChange(){
	if(doHeadDataChange.rt != null)
		clearTimeout(doHeadDataChange.rt);
	doHeadDataChange.rt = setTimeout("doHeadDataChange1()", 100);
};

function doHeadDataChange1() {
	//还款单不做报销标准
	var isHK = getParameter('type');
	if(isHK != null)
		return;
	var headMap = getHeadDsMap();
	var headDataType = getHeadDsDataTypeMap();
	var bodyDsListMap = getBodyDsListMap();
	var bodyList = getBodyList();
	var bodyDataType = getBodyDsDataTypeList();
	var result = getService("webbx_common_service").getHeadReimAction(headMap,headDataType,bodyDsListMap,bodyDataType);
	if(result != null)
		setJkBxHeadDsValue(result);
}

function  doBodyDataChange() {
	if(doBodyDataChange.rt != null)
		clearTimeout(doBodyDataChange.rt);
	doBodyDataChange.rt = setTimeout("doBodyDataChange2()", 100);
}

function doBodyDataChange2() {
	//还款单不做报销标准
	var isHK = getParameter('type');
	if(isHK != null)
		return;
	var headMap = getHeadDsMap();
	var headDataType = getHeadDsDataTypeMap();
	var bodyDsListMap = getBodyDsListMap();//
	var bodyList = getBodyList();
	var bodyDataType = getBodyDsDataTypeList();//
	if(bodyDsListMap != null){
		var resultofbody = getService("webbx_common_service").getBodyReimAction(headMap,headDataType,bodyDsListMap,bodyList,bodyDataType);
		if(resultofbody != null) 
			setJkBxBodyDsValueAno(resultofbody);
	}
}

/*处理参照回车配置事件*/
function beforeProcessReferenceEnter(){
	var headDs = getDataset("bx_bxzb");
	if(headDs == null)
		headDs = getDataset("jk_jkzb");
	var djlxbm = headDs.getSelectedRow().getCellValue(headDs.nameToIndex('djlxbm'));
	return "djlxbm=" + djlxbm;
}

/**
 * 页面参数
 * @return 
 */
function setPageParamMap(key,value){
	if(window.PageParamMap == null)
		window.PageParamMap = new HashMap();
	window.PageParamMap.put(key,value);
}
function getPageParamByKey(key){
	if(window.PageParamMap != null)
		return window.PageParamMap.get(key);
}

function setToObject(key,value){
	window[key] = value;
}
function getFromObject(key){
	return window[key];
}
/**
 * 借款报销页面gridreader
 */

//表头列表grid中UFDouble类型字段的render，用于不同精度
function JkbxJeRender(){};
JkbxJeRender.render = function(rowIndex, colIndex, value, header, cell)
{
	if(value == null || value == '')
		value = "0";
	cell.style.overflow = "hidden";
	cell.style.textOverflow = "ellipsis";
	cell.style.cursor = "default";
	cell.style.textAlign = "center";
	
	var grid = header.owner;
	var ds = grid.model.dataset;
	var pre = 2;
	if(window.bzbmmap != null){
		pre = window.bzbmmap.get(ds.getRow(rowIndex).getCellValue(ds.nameToIndex('bzbm')));
	}
	value = value + "";
	if(value.indexOf(".") == -1){
		value += "."
		for(var i=0; i<pre; i++)
			value += "0";
	}else if(parseFloat(value) == 0){//值为0
		value = "0.";
		for(var i=0; i<pre; i++)
			value += "0";
	}else{//正常浮点数
		value = getDoubleByTrimZero(value);
		if(value.indexOf(".") == -1){
			value += ".";
			for(var i=0; i<pre; i++)
				value += "0";
		}else{
			var arr = value.split(".");
			var c = pre - parseInt(arr[1].length);
			if(c > 0){
				for(var i=0; i<c; i++)
					value += "0";				
			}
		}
	}
	cell.innerHTML  = "<center>" + value + "<center>" ;
};
/*表体grid中UFDouble的列*/
function JkbxBusItemJeRender(){};
JkbxBusItemJeRender.render = function(rowIndex, colIndex, value, header, cell)
{
	if(value == null || value == '')
		value = 0;
	cell.style.overflow = "hidden";
	cell.style.textOverflow = "ellipsis";
	cell.style.cursor = "default";
	cell.style.textAlign = "right";
		
	var grid = header.owner;
	var ds = grid.model.dataset;
	var pre = 2;//默认精度为2
	if(window.bzbmmap != null){
		var headDs = getHeadDs();
		var sRow = headDs.getSelectedRow();
		if(sRow != null){
			var bzbm = sRow.getCellValue(headDs.nameToIndex('bzbm'));
			if(bzbm != null)
				pre = window.bzbmmap.get(bzbm);
		}
	}
	var digit = parseFloat(value);
	value = (digit * Math.pow(10, pre) / Math.pow(10, pre)).toFixed(pre);
	value = value + "";
	if(value.indexOf(".") == -1){
		value += ".";
		for(var i=0; i<pre; i++)
			value += "0";
	}else if(parseFloat(value) == 0){//值为0
		value = "0.";
		for(var i=0; i<pre; i++)
			value += "0";
	}else{//正常浮点数
		value = getDoubleByTrimZero(value);
		if(value.indexOf(".") == -1){
			value += ".";
			for(var i=0; i<pre; i++)
				value += "0";
		}else{
			var arr = value.split(".");
			var c = pre - parseInt(arr[1].length);
			if(c > 0){
				for(var i=0; i<c; i++)
					value += "0";				
			}
		}
	}
	var headerIndex = ds.nameToIndex(header.keyName);
	var isQfw = ds.metadata[headerIndex].qianfenwei;
	if(isQfw != null && isQfw == 'Y'){
		value = formatNum(value, pre);
	}
	cell.innerHTML  = value; 
};

function formatNum(num, digit){   
      if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num))
      	return  num;
      var a = RegExp.$1,b = RegExp.$2,c = RegExp.$3;   
      var re = new RegExp().compile("(\\d)(\\d{3})(,|$)");   
      while(re.test(b)) 
      	b = b.replace(re, "$1,$2$3");   
      if (c && digit && new RegExp("^.(\\d{"+   digit   +"})(\\d)").test(c)){   
      	if (RegExp.$2>4) 
      		c = (parseFloat(RegExp.$1)+1)/Math.pow(10,digit);   
      else 
      		c = "."+ RegExp.$1;}   
      return a +""+ b +""+ (c+"").substr((c+"").indexOf("."));   
} 

/*去掉0*/ 
function getDoubleByTrimZero(value){ 
	var index = -1; 
	var count = value.length-1;
	for(var i=count;i>=0;i--){
		var ch = value.charAt(i);
		if(ch == '.'){
			index = i;
			break;	
		}else if(ch != '0'){
			index = i+1;
			break;	
		}
	}
	return (index == -1) ? value : value.substring(0,index) ;
};